﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;

namespace MT.CustomUserControl.Models
{
    public class MultiComboxItemModel : ObservableObject
    {
        private string itemContent = string.Empty;
        public string ItemContent
        {
            get { return itemContent; }
            set { SetProperty(ref itemContent, value); }
        }

        private bool isChecked = false;
        public bool IsChecked
        {
            get { return isChecked; }
            set { SetProperty(ref isChecked, value); }
        }

        public Action<MultiComboxItemModel> MultiComboxItemCheckedAction;

        /// <summary>
        /// 选中命令
        /// </summary>
        private RelayCommand checkedCommand;
        public RelayCommand CheckedCommand
        {
            get
            {
                if (checkedCommand == null)
                {
                    checkedCommand = new RelayCommand(() =>
                    {
                        MultiComboxItemCheckedAction?.Invoke(this);
                    });
                }

                return checkedCommand;
            }
        }

        public Action<MultiComboxItemModel> MultiComboxItemUnCheckedAction;

        /// <summary>
        /// 取消命令
        /// </summary>
        private RelayCommand unCheckedCommand;
        public RelayCommand UnCheckedCommand
        {
            get
            {
                if (unCheckedCommand == null)
                {
                    unCheckedCommand = new RelayCommand(() =>
                    {
                        MultiComboxItemUnCheckedAction?.Invoke(this);
                    });
                }

                return unCheckedCommand;
            }
        }

        public MultiComboxItemModel(string item_content, Action<MultiComboxItemModel> checkedAction, Action<MultiComboxItemModel> unCheckedAction)
        {
            ItemContent = item_content;
            MultiComboxItemCheckedAction = checkedAction;
            MultiComboxItemUnCheckedAction = unCheckedAction;
        }

        public MultiComboxItemModel(string item_content)
        {
            ItemContent = item_content;
        }
    }
}
